package com.example.demo.mapper;

import com.example.demo.pojo.User;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper {


    @Select("select * from  user where phonenumber = #{phonenumber}")
    User findByphoneNumber(String phonenumber);

    @Select("insert into user(realname, password,address,phonenumber,registrationdate,avatar) values (#{realname}, #{password}, #{address},#{phonenumber},now(),#{avatar})")
    void add(String realname, String password, String address,String phonenumber,String avatar);

    @Update("update user set address = #{address},phonenumber = #{phonenumber},email=#{email} where userid= #{userid}")
    void update(User user);

    /**
     * 更新用户密码
     *
     * @param newPwd 新的密码
     * @param userid 用户ID
     * @return 无返回值，执行更新操作
     *
     * @Update 注解指定了用于更新用户密码的SQL语句，其中#{newPwd}表示新的密码，#{userid}表示用户ID
     */
    @Update("update user set password = #{newPwd} where userid=#{userid}")
    void updatePwd(String newPwd, int userid);

    @Update("update user set accountbalance = #{money} where userid=#{userid}")
    void updatebalance(double money, int userid);

    @Select("select * from user")
    List<User> findAllUsers();

    @Update("update user set avatar = #{avatarurl} where userid=#{userid}")
    void updateavatar(String avatarurl,int userid);

    @Select("select * from  user where email = #{email}")
    User findByemail(String email);

    List<User> findByinfo(String realname, String phonenumber, String email, String address);

    @Update("update user set userstatus = #{status} where userid=#{userid}")
    void updateStatus(int userid, int status);

    @Update("update user set accountbalance = #{accountbalance} where userid=#{userid}")
    void updateaccountbalance(int userid, Double accountbalance);

}
